package com.darksides.lenditweb.client.view;

import com.darksides.lenditweb.client.i18n.UserViewMessages;
import com.darksides.lenditweb.client.presenter.view_interface.IUserViewInterface;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Benjamin Barbier
 *
 */
public class UserView extends Composite implements IUserViewInterface {

	/** Internationalization */
	private final UserViewMessages i18n = GWT.create(UserViewMessages.class);
	
	/** Fields */
	private Button createButton = null;
	private Button getButton = null;
	private Button closeDialogButton = null;
	private Button deleteButton = null;
	
	private Image frFlag = null;
	private Image enFlag = null;
	
	private TextBox id = null;
	private TextBox lastName = null;
	private TextBox firstName = null;
	private TextBox email = null;
	private DialogBox dialogBox = new DialogBox();

	public UserView() {

		id = new TextBox();
		lastName = new TextBox();
		firstName = new TextBox();
		email = new TextBox();
		createButton = new Button( i18n.buttonCreate() );
		getButton    = new Button( i18n.buttonGet() );
		closeDialogButton  = new Button( i18n.buttonClose() );
		deleteButton = new Button( i18n.buttonDelete() );

		frFlag = new Image("/includes/flags/FR.png");
		enFlag = new Image("/includes/flags/EN.png");
		
		Grid createGrid = new Grid( 3, 3 );
		createGrid.setText( 0, 0, i18n.lastname() );
		createGrid.setText( 1, 0, i18n.firstname() );
		createGrid.setText( 2, 0, i18n.email() );
		createGrid.setWidget( 0, 1, lastName );
		createGrid.setWidget( 1, 1, firstName );
		createGrid.setWidget( 2, 1, email );
		createGrid.setWidget( 2, 2, createButton );
		
		Grid getGrid = new Grid(1,4);
		getGrid.setText(0, 0, "User ID: ");
		getGrid.setWidget(0, 1, id);
		getGrid.setWidget(0, 2, getButton);
		getGrid.setWidget(0, 3, deleteButton);
		
		HorizontalPanel flagPanel = new HorizontalPanel();
		flagPanel.add(frFlag);
		flagPanel.add(new HTML("&nbsp;"));
		flagPanel.add(enFlag);
		
		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.add( createGrid );
		mainPanel.add(new HTML("<hr />"));
		mainPanel.add( getGrid );
		mainPanel.add(new HTML("<hr />"));
//		mainPanel.add(new HTML("<a href='?locale=fr'>fr</a> | <a href='?locale=en'>en</a>"));
		mainPanel.add(flagPanel);
		
		
		DecoratorPanel decPanel = new DecoratorPanel();
		decPanel.add(mainPanel);
		
		VerticalPanel page = new VerticalPanel();
		page.add(new HTML("<h1 style='margin:0 0 10px 0;'>Lend-It</h1>"));
		page.add(decPanel);
		
		initWidget( page );
	}

	public HasClickHandlers getFrFlag() {
		return frFlag;
	}
	
	public HasClickHandlers getEnFlag() {
		return enFlag;
	}
	
	public HasClickHandlers getCreateUserButton() {
		return createButton;
	}

	public HasClickHandlers getGetUserButton() {
		return getButton;
	}

	public HasClickHandlers getDeleteUserButton() {
		return deleteButton;
	}
	
	public Widget getCloseDialog() {
		return closeDialogButton;
	}
	
	public HasText getFirstName() {
		return firstName;
	}

	public HasText getLastName() {
		return lastName;
	}

	public HasText getId() {
		return id;
	}
	
	public HasText getEmail() {
		return email;
	}
	
	public Widget getViewWidget() {
		return this;
	}
	
	public DialogBox getDialogBox() {
		return dialogBox;
	}
	
}
